package mn.idax.exchange.otc.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * Create by jack_huang on 2018/8/16
 */
@Getter
@AllArgsConstructor
public enum OrderState {

    /**
     * 订单状态
     1.未支付
     2.买家已支付
     3.卖家标识为放行
     4.已完成
     5.买家取消
     6.过期
     7.申请仲裁（买家 8）
     8.申请仲裁（卖家 9）
     9.仲裁取消
     10.仲裁完成
     */
    STATE_UNPAID(1,11,"未支付"),
    SUB_STATE_INITIALIZATION(1,1,"订单初始子状态"),
    SUB_STATE_UNPAID_FROZEN(1,12,"未支付，已冻结卖家资金"),


    STATE_PAID(2,21,"买家已支付"),//买家打完款
    STATE_TORELEASED(3,11,"卖家标识为放行"),
    STATE_FINISH(4,11,"已完成"),
    STATE_BUYER_CANCEL(5,11,"买家取消"),
    STATE_EXPIRE(6,11,"过期"),
    STATE_BUYER_ARBITRATION(7,11,"买家申请仲裁"),
    STATE_SELLER_ARBITRATION(8,11,"卖家申请仲裁"),
    STATE_CANCEL_ARBITRATION(9,11,"仲裁取消"),
    STATE_FINISH_ARBITRATION(10,11,"仲裁完成"),

    ;

    private Integer code;
    private Integer subCode;
    private String type;

    @Getter
    @AllArgsConstructor
    public enum PushMessageTemplate{
        STATE_UNPAID(1 , "{0}向{1}发来了新的交易请求"),
        SUB_STATE_UNPAID_FROZEN(12 , "订单数字货币已由系统锁定托管，买家在订单有效期内付款并标记付款完成"),
        STATE_TORELEASED(3 , "{0}已确认款项入账，并将给您发放数字货币"),

        STATE_PAID(2 , "{0}已经确认付款"),
        STATE_FINISH(4 , "{0}已经移交数字货币给{1}，交易完成，请给对方评价"),
        STATE_BUYER_CANCEL(5 , "订单已取消，请终止支付"),

        STATE_EXPIRE(6 , "订单已过期，交易取消，请终止支付"),
        STATE_BUYER_ARBITRATION(7 , "买家申请仲裁"),
        STATE_SELLER_ARBITRATION(8 , "卖家申请仲裁"),

        STATE_CANCEL_ARBITRATION(9 , "仲裁取消"),
        STATE_FINISH_ARBITRATION(10 , "仲裁完成"),
        STATE_NOT_FUND(-1 , "暂不支持的状态"),
        ;

        private Integer status;
        private String message;

        public static String getTemplate(Integer orderState){
            for (PushMessageTemplate value : PushMessageTemplate.values()) {
                if (value.getStatus().equals(orderState)){
                    return value.getMessage();
                }
            }
            return STATE_NOT_FUND.getMessage();
        }
    }
    public static Integer getCode(Integer code) {
        for (OrderState orderState : OrderState.values()) {
            if(orderState.getCode().equals(code)){
                return orderState.getCode();
            }
        }
        return null;
    }

    public static String getType(Integer code) {
        for (OrderState orderState : OrderState.values()) {
            if(orderState.getCode().equals(code)){
                return orderState.getType();
            }
        }
        return null;
    }
}
